package gbench.appdemo.ggplot.layer.geom;

import java.util.Arrays;
import java.util.stream.Stream;

import gbench.common.matlib.data.DataReader.DFrame;
import gbench.common.matlib.matrix.MatrixOps.Tuple2;
import gbench.appdemo.ggplot.aes.Aesthetics;
import gbench.appdemo.ggplot.layer.Layer;
import gbench.appdemo.ggplot.plot.panel.SinkPanel;
import gbench.appdemo.ggplot.function.*;

import static gbench.common.matlib.matrix.MatrixOps.Tuple2.*;

/**
 * 向量
 * @author gbench
 *
 */
public class GeomNVec  extends Layer{

    public GeomNVec(DFrame dataframe,Aesthetics mappings) {
        super(mappings, dataframe);
    }
    
    public static GeomNVec geom_nvec(DFrame dataframe,Aesthetics mappings) {
        return new GeomNVec(dataframe,mappings);
    }
    
    public static GeomNVec geom_nvec(Aesthetics mappings) {
        return new GeomNVec(null,mappings);
    }
    
    /**
     * 图层计算
     * 
     * @return
     */
    @Override
    public Stream<Tuple2<Tuple2<Double, Double>, int[]>> evaluate(SinkPanel panel) {
//        final var width = panel.getWidth();
//        final var height = panel.getHeight();
        final var x = this.get("x");
        final var fv = this.getAes("fv", (Fv)null);
        if(fv==null)return Stream.of();
        return x.map(fv).map(pixel->{
            final var clr = Arrays.copyOfRange(pixel.ints(), 2, pixel.size());
            final var coord = TUP2(pixel.get(0),pixel.get(1));
            return TUP2(coord,clr);
        });
    }

}
